package com.ehi.common.config;

import com.ctrip.framework.apollo.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;

/**
 * Created by portz on 7/7/2017.
 */
public class PropertiesUtil {

    @Autowired
    private ConfigProperties configProperties;

    private static ConfigProperties staticConfigProperties;

    @PostConstruct
    public void init() {
        PropertiesUtil.staticConfigProperties = configProperties;
    }

    public static String get(String key, String defaultValue) {
        String useConfigCenter = System.getProperty("useConfigCenter", "N");
        if ("Y".equalsIgnoreCase(useConfigCenter)) {
            return ConfigService.getAppConfig().getProperty(key, defaultValue);
        } else {
            return staticConfigProperties.get(key, defaultValue);
        }
    }


}
